<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>文献资源管理系统-用户管理</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="文献资源管理系统-用户管理">
<meta name="description" content="文献资源管理系统-用户管理">
<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<!-- <link href="css/style.min.css" rel="stylesheet"> -->

<!--标签插件-->
<link rel="stylesheet" href="js/jquery-tags-input/jquery.tagsinput.min.css">
<link href="css/style.min.css" rel="stylesheet">
</head>
  <style>
    .col-lg-12{
      margin: auto;
      top: 17px;
      left: 0;
      bottom: 0;
      right: 0;
      position: absolute;
    }
    body {
      margin: 0;
    }
    #button {
      background-color: #33cabb; 
      border-left-color:#33cabb;
      border-right-color:#33cabb;
      border-top-color:#33cabb;
      border-bottom-color:#33cabb;
    }
   
  </style>
 
<body>

<div class="lyear-layout-web" id="app">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <div class="lyear-layout-sidebar-scroll">
      <nav class="sidebar-main">
        <ul class="nav nav-drawer">       
        </ul>
      </nav>
    </div>
    <!--End 左侧导航-->
    
    <!--头部信息-->
 
    <!--End 头部信息-->
    
    <!--页面主要内容-->

    <main class="lyear-layout-content" >
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12" >
            <div class="card">
              <div class="card-toolbar clearfix">
                <form class="pull-right search-bar" method="get" action="#!" role="form">
                  <div class="input-group">
                    <div class="input-group-btn">
                      <input type="hidden" name="search_field" id="search-field" value="title">
                      <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                        登录名 <span class="caret"></span>
                      </button>
                    </div>
                    <input type="text" class="form-control"  name="keyword" v-model="username.userName" v-on:keyup="getlist(1)"  placeholder="请输入名称">
                  </div>
                </form>
                <div class="toolbar-btn-action">
                  <a class="btn btn-primary m-r-5" type="button" data-toggle="modal" @click="click()" data-target="#myModal"><i class="mdi mdi-plus" ></i> 新增</a>
                  <el-button  class="btn btn-danger" type="warning" style="background-color:#f96868;" @click="removeBatch(sels)" :disabled="this.sels.length === 0||this.disabled"><i class="mdi mdi-window-close"></i>批量删除</el-button>
                </div>
              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <template>
                      <el-table
                        v-loading="loading"
                        element-loading-text="拼命加载中"
                        :data="list"
                        style="width: 100%"  @selection-change="selsChange"  >
                    <el-table-column type="selection" width="65"></el-table-column>
                        <!-- <el-table-column
                          prop="userId"
                          label="序号"
                          width="180">
                        </el-table-column> -->
                        <el-table-column
                          prop="userName"
                          label="登录名"
                          width="180">
                        </el-table-column>
                        <el-table-column
                          prop="userRealName"
                          label="真实姓名">
                        </el-table-column>
                        <el-table-column
                          prop="eMail"
                          label="邮件地址">
                        </el-table-column>
                        <el-table-column
                          prop="roleName"
                          label="管理员">
                        </el-table-column>
                        <el-table-column
                        prop="organName"
                        label="机构">
                      </el-table-column>
                      <!-- <el-table-column
                      prop="userRoles"
                      label="角色">
                    </el-table-column> -->
                      <el-table-column
                      prop="userCdate"
                      label="创建时间">
                    </el-table-column>
                    <el-table-column
                    prop="userLoginDate"
                    label="登陆时间">
                  </el-table-column>
                  <el-table-column label="操作" align="center" min-width="100">
              　　　　<template slot-scope="scope">
                          <div class="btn-group">
                            <a class="btn btn-xs btn-default" @click="pwd(scope.row.userId)" type="button" data-toggle="modal" data-target="#myModal3" title="重置密码" data-toggle="tooltip"><i class="mdi mdi-check"></i></a>
                            <a class="btn btn-xs btn-default" @click="unit(scope.row.userId)"  type="button" data-toggle="modal" data-target="#myModal2" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                          </div>
            
              　　　　</template>
              　　</el-table-column>
                      </el-table>
                      
                    </template>
                   
                  </table>
                </div>

                <nav>
                  <ul class="pagination pagination-circle">
                    <li class="active"><a>{{totals}}</a></li>
                    <li>
                      <a type="button" @click="getlist(prePage)">
                        <span><i class="mdi mdi-chevron-left" ></i></span>
                      </a>
                    </li>
                    <li ><a>{{currentPage}}</a></li>
                    <li>
                      <a type="button" @click="getlist(nextPage)">
                        <span><i class="mdi mdi-chevron-right"></i></span>
                      </a>
                    </li>
                  </ul>
                </nav>  


                <!-- 添加模态框（Modal） -->
                <form action=""  class="form-horizontal" role="form">
                  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <h4 class="modal-title" id="myModalLabel">
                                      用户添加
                                  </h4>
                                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                      &times;
                                  </button>
                              </div>
                              <div class="modal-body" style="height: 100%;">
                                  <div class="form-group">
                                      <label for="lastname" class="col-sm-3 control-label">登录名</label>
                                      <div class="col-sm-7">
                                        <input class="form-control" type="text" v-model="user.userName" placeholder="登录名">
                                      </div>
                                  </div>
                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">密码</label>
                                    <div class="col-sm-7">
                                      <input class="form-control" type="text" v-model="user.userPwd" placeholder="密码">
                                    </div>
                                </div>
                                <div class="form-group">
                                  <label for="lastname" class="col-sm-3 control-label">真实姓名</label>
                                  <div class="col-sm-7">
                                    <input class="form-control" type="text" v-model="user.userRealName" placeholder="真实姓名">
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label for="lastname" class="col-sm-3 control-label">手机号</label>
                                  <div class="col-sm-7">
                                    <input class="form-control" type="text" v-model="user.userPhone" placeholder="手机号">
                                  </div>
                                </div>
                              <div class="form-group">
                                <label for="lastname" class="col-sm-3 control-label">邮件地址</label>
                                <div class="col-sm-7">
                                  <el-input placeholder="邮件地址"  v-model="user.eMail" >
                                    <template slot="append">.com</template>
                                  </el-input>
                                  <!-- <input class="form-control" type="text" v-model="user.eMail" placeholder="邮件地址"> -->
                                </div>
                              
                            </div>
                            <div class="form-group">
                              <label for="lastname" class="col-sm-3 control-label">机构</label>
                              <div class="col-sm-7">
                                <select v-model="user.institutions" class="form-control">
                                  <option v-for="(item,index) in organ" :value="item.id">{{item.name}}</option>
                                </select>
                              </div>
                          </div>
                          <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">管理员</label>
                            <div class="col-sm-7">
                              <select v-model="user.userAdmin" class="form-control">
                                <option v-for="(item,index) in admin" :value="item.roleId">{{item.roleName}}</option>
                              </select>
                            </div>
                        </div>
                        <div class="form-group">
                          <label for="lastname" class="col-sm-3 control-label">文献类型</label>
                          <div class="col-sm-7">
                            全部<input  type="radio" v-model="user.resourceType" style="margin-left: 6px" value="0">
                            期刊<input  type="radio" v-model="user.resourceType" style="margin-left: 6px" value="1">
                            非刊<input  type="radio" v-model="user.resourceType" style="margin-left: 6px" value="2">
                          </div>
                      </div>
                        <!-- <div class="form-group">
                          <label for="lastname" class="col-sm-3 control-label">角色</label>
                          <div class="col-sm-7">
                            
                            <input class="form-control" type="text" v-model="user.userRoles" placeholder="角色">
                          </div>
                      </div> -->
                              </div>
                              <div class="modal-footer">
                                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                  <el-button id="button" data-dismiss="modal"  class="btn btn-default" type="primary" :loading="loading"  @click.native.prevent="useradd" >提交</el-button>

                              </div>
                          </div><!-- /.modal-content -->
                      </div><!-- /.modal -->
                  </div>
                </form>
                <!-- 修改模态框（Modal） -->
                <form action=""  class="form-horizontal" role="form">
                  <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <h4 class="modal-title" id="myModalLabel">
                                      用户修改
                                  </h4>
                                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                      &times;
                                  </button>
                              </div>
                              <div class="modal-body" style="height: 100%;">
                                  <div class="form-group">
                                      <label for="lastname" class="col-sm-3 control-label">登录名</label>
                                      <div class="col-sm-7">
                                        <input class="form-control" type="text" v-model="user2.userName" placeholder="登录名">
                                      </div>
                                  </div>
                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">密码</label>
                                    <div class="col-sm-7">
                                      <input class="form-control" type="text" v-model="user2.userPwd" placeholder="密码">
                                    </div>
                                </div>
                                <div class="form-group">
                                  <label for="lastname" class="col-sm-3 control-label">真实姓名</label>
                                  <div class="col-sm-7">
                                    <input class="form-control" type="text" v-model="user2.userRealName" placeholder="真实姓名">
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label for="lastname" class="col-sm-3 control-label">手机号</label>
                                  <div class="col-sm-7">
                                    <input class="form-control" type="text" v-model="user2.userPhone" placeholder="手机号">
                                  </div>
                                </div>
                              <div class="form-group">
                                <label for="lastname" class="col-sm-3 control-label">邮件地址</label>
                                <div class="col-sm-7">
                                  <el-input placeholder="邮件地址"  v-model="user2.eMail" >
                                    <template slot="append">.com</template>
                                  </el-input>
                                </div>
                            </div>
                            <div class="form-group">
                              <label for="lastname" class="col-sm-3 control-label">机构</label>
                              <div class="col-sm-7">
                                <select v-model="user2.institutions" class="form-control">
                                  <option v-for="(item,index) in organ" :value="item.id">{{item.name}}</option>
                                </select>
                              </div>
                          </div>
                          <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">管理员</label>
                            <div class="col-sm-7">
                              <select v-model="user2.userAdmin" class="form-control">
                                <option v-for="(item,index) in admin" :value="item.roleId">{{item.roleName}}</option>
                              </select>
                            </div>
                        </div>
                        <div class="form-group">
                          <label for="lastname" class="col-sm-3 control-label">文献类型</label>
                          <div class="col-sm-7">
                          <span v-if="user2.resourceType == 0">
                              全部<input  type="radio" v-model="user2.resourceType" style="margin-left: 6px" checked value="0">
                          </span>
                          <span v-if="user2.resourceType != 0">
                            全部<input  type="radio" v-model="user2.resourceType" style="margin-left: 6px" value="0">
                          </span>
                          <span v-if="user2.resourceType == 1">
                            期刊<input  type="radio" v-model="user2.resourceType" style="margin-left: 6px" checked  value="1">
                          </span>
                          <span v-if="user2.resourceType != 1">
                            期刊<input  type="radio" v-model="user2.resourceType" style="margin-left: 6px"   value="1">
                          </span>
                          <span v-if="user2.resourceType == 2">
                            非刊<input  type="radio" v-model="user2.resourceType" style="margin-left: 6px"  checked value="2">
                          </span>
                          <span v-if="user2.resourceType != 2">
                            非刊 <input  type="radio" v-model="user2.resourceType" style="margin-left: 6px"  value="2">
                          </span>
                          </div>
                      </div>
                        <!-- <div class="form-group">
                          <label for="lastname" class="col-sm-3 control-label">角色</label>
                          <div class="col-sm-7">
                            <input class="form-control" type="text" v-model="user2.userRoles" placeholder="角色">
                          </div>
                      </div> -->
                              </div>
                              <div class="modal-footer">
                                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                  <el-button id="button" data-dismiss="modal" class="btn btn-primary" type="primary"  @click.native.prevent="userupdate" :loading="loading">提交</el-button>
                              </div>
                          </div><!-- /.modal-content -->
                      </div><!-- /.modal -->
                  </div>
                </form>
                 <!-- 重置密码模态框（Modal） -->
                 <form action=""  class="form-horizontal" role="form">
                  <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog">
                          <div class="modal-content">
                              <div class="modal-header">
                                  <h4 class="modal-title" id="myModalLabel">
                                    重置密码
                                  </h4>
                                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                      &times;
                                  </button>
                              </div>
                              <div class="modal-body" style="height: 100%;">
                                 
                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">重置密码</label>
                                    <div class="col-sm-7">
                                      <input class="form-control" type="text" v-model="user.userPwd" placeholder="重置密码">
                                    </div>
                                </div>
                              </div>
                              <div class="modal-footer">
                                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                  <!-- <input type="button"  data-dismiss="modal" class="btn btn-primary" @click="pwdupdate()" value="提交"/> -->
                                  <el-button id="button" data-dismiss="modal"  class="btn btn-primary" type="primary"  @click.native.prevent="pwdupdate" :loading="loading">提交</el-button>
                              </div>
                          </div><!-- /.modal-content -->
                      </div><!-- /.modal -->
                  </div>
                </form>
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<!-- <script type="text/javascript" src="js/main.min.js"></script> -->
<!--标签插件-->
<script src="js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>

 <script src="https://cdn.bootcss.com/vue/2.6.9/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>

    <!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script type="text/javascript">
new Vue({
  el:"#app",
  data:{
    list:[],
    admin:[],
    organ:[],
    loading: false,
    username:{},

    currentPage:1, //当前页码
    size:5, 
    totals:"",
    prePage:1,
    nextPage:1,
    totalPage:1, //总页数

    user:{},
    user2:{},
    pwdid:"",
    upid:"",
    sels: [],//选中显示的值
    disabled:true
    
  },
  created () {
    this.getlist(1);
  },
  methods: {
    getlist(currentPage){

      this.loading = true;
      setTimeout(() => {
      this.loading = false;
        
      axios.post("http://29n01o8660.oicp.vip/server/findByAllname/"+this.currentPage+"/"+this.size,this.username)
      .then(res => {
        this.list = res.data.data.rows;
        // alert(JSON.stringify(this.list))
        this.totals = res.data.data.total;
        this.currentPage = currentPage;
        this.totalPage = Math.ceil(this.totals/this.size);
        this.prePage = 
        currentPage>1?currentPage-1:currentPage;
        this.nextPage = currentPage<this.totalPage?currentPage+1:currentPage;
      
      })
      .catch(err => {
        console.error(err); 
      })
    }, 2000);
      
      axios.get("http://29n01o8660.oicp.vip/server/findallrole")
      .then(res => {
        this.admin = res.data
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      }),
      axios.get("http://29n01o8660.oicp.vip/server/findorgantree")
      .then(res => {
        this.organ = res.data
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })


    },
    useradd(){
      
      axios.post("http://29n01o8660.oicp.vip/server/userinsert",this.user)
      .then(res => {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.$message({
          message: '恭喜你，添加成功',
          type: 'success'
          });

        }, 2000);
        
        this.getlist(1)
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
   
    },
    userupdate(){
      this.upid = window.localStorage.getItem("upid");
      axios.put("http://29n01o8660.oicp.vip/server/userupdate/"+this.upid,this.user2)
      .then(res => {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;

          this.$message({
          message: '恭喜你，修改成功',
          type: 'success'
        });

        }, 2000);

        this.getlist(1)
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
    },
    pwd(pwdid){
      window.localStorage.setItem("pwdid",pwdid);
      this.user={}  //清空
    },
    unit(upid){
      window.localStorage.setItem("upid",upid);
      axios.get("http://29n01o8660.oicp.vip/server/findById/"+upid)
      .then(res => {
        
        this.user2 = res.data
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
    },
    pwdupdate(){
      this.pwdid = window.localStorage.getItem("pwdid");
      axios.put("http://29n01o8660.oicp.vip/server/userupdatepwd/"+this.pwdid,this.user)
      .then(res => {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;

          this.$message({
          message: '恭喜你，重置密码成功',
          type: 'success'
           });

        }, 2000);

        this.getlist(1)
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
    },
    click(){
      this.user={}
    },
    selsChange(sels) {      
        //被选中的行组成数组 
        this.sels = sels;
        // alert(JSON.stringify(this.sels))
        //遍历被选中行数所组成的数组
        for(let element of this.sels){
        //如果视频正在转码或者等待转码,禁用按钮,结束方法
          if(element.status == 'waiting'||element.progress){
            this.disabled = true;
            return;
          }
             //如果没有视频正在转码或者等待转码,按钮可用
            this.disabled = false;
        }
    },
    removeBatch(rows){  //批量删除
      var ids = [];
      //alert(JSON.stringify(rows))
      rows.forEach(element =>{
        ids.push(element.userId)
      })
      alert(ids)
      this.$confirm('确定要删除选中的文件吗?','提示').then(() =>{
        axios.get("http://29n01o8660.oicp.vip/server/userbulkdel/"+ids)
        .then(res => {
          this.loading = true;
        setTimeout(() => {
          this.loading = false;

          this.$message({
          message: '恭喜你，批量删除成功',
          type: 'success'
           });

          }, 2000);

          this.getlist(1);
          console.log(res)
        })
        .catch(err => {
          console.error(err); 
        })
        // $.get('http://localhost:8090/userbulkdel',{
        //   ids:ids
        // }).then(dara =>{
        //   //刷新
        //   this.getlist(1);
        // })
      }).catch(()=>{});
    },

  }
})


</script>
</body>
</html>